var pageContext = new PageContext(settings||{});
pageContext.formInit = function(layero){
	
}

pageContext.exportData = function(me){
	 var val = $(me).attr("val");
	 var label = $(me).attr("label");
	 var url = ($(me).attr("url"));
//	 url = "http://127.0.0.1/sys/file/download/dd.xlsx";
	 var search = $("#search").text();
	 search = search.replace(/<_>/g,"&").replace(/<->/g,"=");
	 search = JSON.parse(search);
	 console.log(search);
	 var from = $("#step1Form");
	 var searchParames = '' ; 
     searchParames = from.formSerializeNotBlank();
     console.log(searchParames);
	 var p=search.para,filter=search.filter;
	 if(filter){
		 try {
			filter = JSON.stringify(filter);
		} catch (e) {
		}
	 }
	 if(p=="" || !p){
		 p = "1=1"
	 }
	 if(!filter){
		 filter = "";
	 }
	 url += encodeURIComponent("?"+p+"&filter="+encodeURIComponent(filter)+"&"+searchParames);
	 
	 $("#newPage").closest("a").attr("href",url).attr("title",$("#tableName").val()+".xlsx");
	 $('#newPage').downloadr({url:window.global.ctx+"/data/table/data/todowndialog?url="+encodeURI(url),title:"导出"});
	 $("#newPage").click();
	 setTimeout(pageInit,1000)
     return false;
}
jQuery(function($) {
	pageContext.init();
//	  $('.fields').iCheck({
//	      checkboxClass: 'icheckbox_square-blue',
//	      radioClass: 'iradio_square-blue',
//	      increaseArea: '20%' // optional
//	    });
	$(".fields").addClass('ace ace-checkbox-2')
	.wrap('<label />')
	.after('<span class="lbl align-top" />') 
	$(".checkBtn").on("click",function(){
		$('.fields').iCheck('check');
	});
	$(".noSyscheckBtn").on("click",function(){
		$('.ffalse').iCheck('check');
	});
	$(".uncheckBtn").on("click",function(){
		$('.fields').iCheck('uncheck');
	});
	$("#step1Form").validationEngine('attach', {promptPosition : "topLeft", autoPositionUpdate : true});
	var $validation = false;
	$('#fuelux-wizard-container')
	.ace_wizard({
		//step: 2 //optional argument. wizard will jump to step "2" at first
		//buttons: '.wizard-actions:eq(0)'
	})
	.on('actionclicked.fu.wizard' , function(e, info){
		console.log()
		console.log(info)
		if(info.step == 1 && info.direction=="next") {
			 var from = $("#step1Form");
			 if(from.validationEngine("validate")){
				 var searchParames = '' ; 
		         searchParames = from.formSerializeNotBlank();
		         console.log(searchParames);
		         var len = $(".fields:checkbox:checked").length;
		         if(!searchParames || len<=0 || searchParames.length<=0){
		        	 alert("请选择需要导出的字段！");
		        	 return false;
		         }
			 }
		}
	})
	.on('finished.fu.wizard', function(e,info) {
		bootbox.dialog({
			message: "您的导出数据流程已完成！", 
			buttons: {
				"success" : {
					"label" : "OK",
					"className" : "btn-sm btn-primary"
				}
			}
		});
	}).on('stepclick.fu.wizard', function(e,info){
		console.log("click")
		console.log(e)
		console.log(info)
		//e.preventDefault();//this will prevent clicking and selecting steps
	}).on('changed.fu.wizard', function(e,info){
		console.log()
		console.log("changed"+":")
		console.log(e)
		console.log(info)
		//e.preventDefault();//this will prevent clicking and selecting steps
	});
//	previous	Moves to the previous step
//	next	Moves to the next step
//	selectedItem	Returns the current step index
	$('#modal-wizard-container').ace_wizard();
	$('#modal-wizard .wizard-actions .btn[data-dismiss=modal]').removeAttr('disabled');
	 
});

